package MapReduce.ETL;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import java.io.IOException;

public class etlMain {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        args = new String[]{"D:\\中国科学院大学硕士\\学习类文件夹\\BigDataDev\\Input\\inputlog\\web.log","D:\\中国科学院大学硕士\\学习类文件夹\\BigDataDev\\Output\\output5"};
        // 1 获取Job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2 获取jar包路径
        job.setJarByClass(etlMain.class);

        // 3 关联Mapper和Reducer
        job.setMapperClass(etlMapper.class);
//        job.setReducerClass(reduceJoinReducer.class);

        // 4 设置map输出的K V类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

//        // 5 设置最终的输出K V类型
//        job.setOutputKeyClass(Text.class);
//        job.setOutputValueClass(NullWritable.class);

        // 此处不需要reduce阶段因为数据已经在map阶段处理完成
        job.setNumReduceTasks(0);


        // 6 设置输入输出路径
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        // 7 提交Job
        boolean waitForCompletion = job.waitForCompletion(true);
        System.exit(waitForCompletion ? 0 : 1);
    }
}
